package cn.dengta.webapp.trade.entity;

import cn.dengta.common.model.Status;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import cn.dengta.webapp.trade.model.PayPlatform;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.Cmp;

@Setter
@Getter
@Accessors(chain = true)
@TableName(value = "tr_recharge_channel_config", autoResultMap = true)
public class RechargeChannelConfig extends TimeBasedEntity {

	/** 1=充值；2=提现 */
	private Integer type;
	/** 别名 程序中的标识  注意与 nacos 中的别名保持一致 */
	private String alias;
	/** 服务id */
	private String serviceId;
	private String name;
	/** 3=微信；4=GeeWallet; 6=NganPay;7=PayerMax；8=支付宝;9=美事通 */
	private Integer platform;
	/** 当有多个时,那个作为默认(比如 ：微信、微信小程序): 0=关闭；1=正常 */
	private Integer subMasterPay;
	/** 0=关闭；1=正常 */
	private Integer status;
	/** 0=关闭；1=默认支付 */
	private Integer pay;

	public static final String TYPE = "type";
	public static final String SHOW_PAY = "show_pay";
	public static final String NAME = "name";
	public static final String STATUS = "status";
	public static final String PLATFORM = "platform";
	public static final String SUB_MASTER_PAY = "sub_master_pay";
	public static final String PAY = "pay";

	transient PayPlatform payPlatform;

	/** 是否可用 */
	public boolean canStatus() {
		return Cmp.eq(this.status, Status.YES.value);
	}

	public String getStatus_() {
		return Status.asBoolean(status) ? "开启" : "关闭";
	}

	public PayPlatform getPayPlatform() {
		if (payPlatform == null) {
			payPlatform = PayPlatform.of(this.platform);
		}
		return payPlatform;
	}

	public boolean canCash() {
		return hasCash() && Cmp.eq(this.status, Status.YES.value);
	}

	public boolean canRecharge() {
		return hasRecharge() && Cmp.eq(this.status, Status.YES.value);
	}

	public boolean hasRecharge() {
		return Cmp.eq(this.type, 1);
	}

	public boolean hasCash() {
		return Cmp.eq(this.type, 2);
	}

	public boolean hasWxOrGeeWallet() {
		return Cmp.eq(this.type, 1) && (Cmp.eq(this.platform, PayPlatform.Wxpay.value) || Cmp.eq(this.platform, PayPlatform.GeeWallet.value));
	}

}
